<template>
  <div class="index-wrap">
    <div class="index-left">
      <div class="index-left-block">
        <h2>全部产品</h2>
        <template v-for="product of productList">
          <div :key='product.index'>
          <h3 v-text="product.title"></h3>
          <ul>
            <li v-for="item of product.list" :key="item.key">
              <router-link :to="item.url" v-text="item.name"></router-link>
              <span v-if="item.hot" class="hot-tag">HOT</span>
            </li>
          </ul>
          <div v-if="!product.last" class="hr"></div>
          </div>
        </template>
      </div>
      <div class="index-left-block lastest-news">
        <h2>最新消息</h2>
        <ul>
          <li v-for="item of newList" :key="item.id">
            <a :href="item.url" v-text="item.title" class="new-item"></a>
          </li>
        </ul>
      </div>
    </div>
    <div class="index-right">
      <!-- @onchange接受子组件的触发onchange，执行doSomethingOnSlidChange -->
      <slide-show v-bind:slides="slides" @onchange="doSomethingOnSlidChange"></slide-show>
      <div class="index-board-list">
        <div class="index-board-item" 
        v-for="(item,index) of boardList" 
        :key="item.id" 
        v-bind:class="[{'line-last':index % 2 !==0},'index-board-'+item.id]">
          <div class="index-board-item-inner">
            <h2 v-text="item.title"></h2>
            <p v-text="item.description"></p>
            <div class="index-board-button">
              <router-link :to="item.href" class="button">立即购买</router-link>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import slideShow from '../components/slideShow'
export default{
  components: {
    slideShow
  },
  created: function () {
    this.$http.get('/api/getNewsList')
    .then((data) => {
      console.log(data)
      this.newList = data.data
    })
    .catch((error) => {
      console.log(error)
    })
  },
  methods: {
    doSomethingOnSlidChange (msg) {
      // console.log('doSomethingOnSlidChange:' + msg)
    }
  },
  data () {
    return {
      slides: [
        {
          src: require('../assets/slideShow/pic1.jpg'),
          title: '旧货回收',
          href: 'detail/analysis'
        },
        {
          src: require('../assets/slideShow/pic2.jpg'),
          title: '网络维修',
          href: 'detail/count'
        },
        {
          src: require('../assets/slideShow/pic3.jpg'),
          title: '导游地陪',
          href: 'detail/publish'
        },
        {
          src: require('../assets/slideShow/pic4.jpg'),
          title: '生活配送',
          href: 'detail/forecast'
        }
      ],
      boardList: [
        {
          title: '网络维修',
          description: '电脑维修-网络组建-网络修复',
          id: 'car',
          toKey: 'analysis',
          saleout: false,
          href: 'detail/count'
        },
        {
          title: '旧货回收',
          description: '上门高价回收电脑笔记本台式机',
          id: 'earth',
          toKey: 'count',
          saleout: false,
          href: 'detail/analysis'
        },
        {
          title: '生活配送',
          description: '桶装矿泉水，一个电话，服务到家',
          id: 'loud',
          toKey: 'forecast',
          saleout: true,
          href: 'detail/forecast'
        },
        {
          title: '导游地陪',
          description: '旅游选择我，将是您正确的选择！',
          id: 'hill',
          toKey: 'publish',
          saleout: false,
          href: 'detail/publish'
        }
      ],
      newList: [],
      productList: {
        pc: {
          title: '主打服务',
          list: [
            {
              name: '网络维修',
              url: 'detail/count',
              key: 'starcraft'
            },
            {
              name: '生活配送',
              url: 'detail/forecast',
              key: 'warcraft'
            },
            {
              name: '旧货回收',
              url: 'detail/analysis',
              hot: true,
              key: 'overwatch'
            },
            {
              name: '导游地陪',
              url: 'detail/publish',
              key: 'hearstone'
            }
          ]
        },
        app: {
          title: '友情推荐',
          last: true,
          list: [
            {
              name: '91助手',
              url: 'http://weixin.com'
            },
            {
              name: '产品助手',
              url: 'http://twitter.com',
              hot: true
            },
            {
              name: '智能地图',
              url: 'http://maps.com'
            },
            {
              name: '团队语音',
              url: 'http://phone.com'
            }
          ]
        }
      }
    }
  }
}
</script>

<style scoped>
  .index-wrap {
    width: 1200px;
    margin: 0 auto;
    overflow: hidden;
  }
  .index-left {
    float: left;
    width: 300px;
    text-align: left;
  }
  .index-right {
    float: left;
    width: 900px;
  }
  .index-left-block {
    margin: 15px;
    background: #fff;
    box-shadow: 0 0 1px #ddd;
  }
  .index-left-block .hr {
    margin-bottom: 20px;
  }
  .index-left-block h2 {
    background: #4fc08d;
    color: #fff;
    padding: 10px 15px;
    margin-bottom: 20px;
  }
  .index-left-block h3 {
    padding: 0 15px 5px 15px;
    font-weight: bold;
    color: #222;
  }
  .index-left-block ul {
    padding: 10px 15px;
  }
  .index-left-block li {
    padding: 5px;
  }
  .index-board-list {
    overflow: hidden;
  }
  .index-board-item {
    float: left;
    width: 400px;
    background: #fff;
    box-shadow: 0 0 1px #ddd;
    padding: 20px;
    margin-right: 20px;
    margin-bottom: 20px;
  }
  .index-board-item-inner {
    min-height: 125px;
    padding-left: 120px;
  }
  .index-board-car .index-board-item-inner{
    background: url(../assets/images/1.png) no-repeat;
  }
  .index-board-loud .index-board-item-inner{
    background: url(../assets/images/2.png) no-repeat;
  }
  .index-board-earth .index-board-item-inner{
    background: url(../assets/images/3.png) no-repeat;
  }
  .index-board-hill .index-board-item-inner{
    background: url(../assets/images/4.png) no-repeat;
  }
  .index-board-item h2 {
    font-size: 18px;
    font-weight: bold;
    color: #000;
    margin-bottom: 15px;
  }
  .line-last {
    margin-right: 0;
  }
  .index-board-button {
    margin-top: 20px;
  }
  .lastest-news {
    min-height: 512px;
  }
  .hot-tag {
    background: red;
    color: #fff;
  }
  .new-item {
    display: inline-block;
    width: 230px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
</style>
